package Master;

/**
 * Project:    metsysdirg
 * File Name: Task.java
 * Change History:
 *     ********************************
 *     1.0     5/14/2011    Hengfeng Li
 *         Create the skeleton file
 *     ********************************
 *
 */

import java.util.ArrayList;
import java.util.Collections;

/**
 * TaskPlan class. Provides a plan of tasks input from
 * ClientGUI.
 */
public class TaskPlan {

	/** The ID of the Task Plan*/
	private int taskPlanID;
	
    /** The list of tasks input from xml files */
    private ArrayList<Task> tasks;

    /** The list of worker resources */
    private ArrayList<Resource> resources;

    /** The budget of this task plan, and the unit is a dollar */
    private float budget;

    /**
     * The task plan must be finished less than this time,
     * and the unit is a second.
     */
    private float timeRequired;
    
    /** The file path of the task plan */
    private String filepath;

    public TaskPlan(int taskPlanID, float budget, float timeRequired, String filepath){
        this.budget = budget;
        this.timeRequired = timeRequired;
        this.taskPlanID = taskPlanID;
        this.filepath = filepath;
        
        tasks = new ArrayList<Task>();
        resources = new ArrayList<Resource>();
    }

    public float getBudget(){
        return budget;
    }

    public float getTimeRequired(){
        return timeRequired;
    }

    public void addTask(Task task) {
        this.tasks.add(task);
    }

    public void addResource(Resource resource){
        this.resources.add(resource);
    }

    public ArrayList<Task> getTasks(){
        return tasks;
    }

    public ArrayList<Resource> getResources(){
        return resources;
    }

    public void sortResources(){
        Collections.sort(this.resources);
    }
    
    public Resource getFirstResource(){

        // find the first resource which is available
        for(Resource resource : resources){
            if(resource.isAvailable()){
                return resource;
            }
        }
    	return null;
    }

	public int getTaskPlanID() {
		return taskPlanID;
	}

	public String getFilepath() {
		return filepath;
	}
	
	public void setBudget(float budget) {
		this.budget = budget;
	}

	public void setTimeRequired(float timeRequired) {
		this.timeRequired = timeRequired;
	}
}
